import router from '@/router'
import { GET_TOKEN } from '@/utils/token'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({ showSpinner: false })

// 路由前置守卫
router.beforeEach((to, from, next) => {
  NProgress.start();
  const TOKEN = GET_TOKEN()
  // 如果没有token且去的路由不是login
  if (!TOKEN && to.path !== '/login') {
    next('/login')
    NProgress.done();
  } else {
    next()
  }
})

router.afterEach((to) => {
  document.title = "硅谷甄选" + to.meta.title
  NProgress.done();
})